<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //实现递归深层拷贝
        function deepCopy(target,cache = new Map()){
            if(target.typeof !== 'object'){
                return target
            }
            if(cache.has(target)){
                return cache.get(target)
            }
           var result = Array.isArray(target)? [] : {};
           cache.set(target,result)
           if(Array.isArray(target)){
            for(var i in target){
                result.push(deepCopy(target[i],cache))
            }
           } else{
            for(var k in target){
                result[k] = deepCopy(target[k],cache)
            } 
           }
           return result
        }
        var obj1 = { name: '文理东', hobby: ['看书', '敲代码'], a: [1, 2] }

      obj1.hobby.push(obj1.a)
      obj1.a.push(obj1.hobby)

      var obj2 = deepCopy(obj1)
      console.log(obj2)
    </script>
</body>
</html>